<template>
  <div class="container contract-review mb70">
    <p class="bread">
      <a href="#/index/tms-order-list" class="font-s-18">交易监控订单管理-监控员</a> >
      <a href="javascript:void(0);" class="font-s-16">详情</a>
    </p>
    <div class="content bg-c-fff">
      <div class="rel">
        <h3 class="tc">交易监控流程图</h3>
        <div class="abs title-btn" v-if="this.state<6">
          <button class="white-button xl-btn-css" @click="onMsg">发送消息</button>
          <button class="white-button xl-btn-css" @click="errShow=true">纠错申请</button>
          <button class="white-button xl-btn-css" @click="clockButton">设置提醒闹钟</button>
        </div>
      </div>
      <div class="progress-box rel">
        <company-name-container :companyNames="companyNames"></company-name-container>
        <div class="line" :class="{center: companyNames.length===2}" :style="{height: (events.length+0.5)*90+20+'px'}" v-show="events.length">
          <div class="arrow"></div>
        </div>
        <event-item v-for="(item,index) in events" :key="index" :pstate="item.state" :totalSides="companyNames.length" :side="item.side" :content="item.content" :files="item.files" :eventId="item.id" :isAudit="true" :serviceId="id" tradeType="trade" :isProgressing="state===5"></event-item>
      </div>
      <p :class="{tc: companyNames.length===2}" v-show="events.length">交易监控结束</p>
    </div>
    <div class="content bg-c-fff">
      <h4> 备注信息：</h4>
      <div class="note-box">{{remark}}</div>
    </div>
    <vodal :show="megShow" animation="zoom" :width="420" :height="345" @hide="megShow=false">
      <div class="vodal-main message">
        <h4>发送消息</h4>
        <div class="con">
          <p>消息内容：
            <textarea class="vt" v-model="msgContent">
            </textarea>
          </p>
          <div class="fix">
            <span class="flo-left">多方提醒：</span>
            <ul class="flo-left">
              <li v-for="(item, i) in businessList">
                <input type="checkbox" :id="i" :value="item.memberId" v-model="checkedNames">
                <label :for="i">{{item.memberName}}</label>
              </li>
            </ul>
          </div>
          <div class="auto tc">
            <button class="blue-button xl-btn-css" @click="onMsgSubmit">确认发送</button>
          </div>
        </div>
      </div>
    </vodal>
    <vodal :show="errShow" animation="zoom" :width="420" :height="250" @hide="errShow=false">
      <div class="vodal-main">
        <h4>纠错申请</h4>
        <div class="con">
          <p>备注信息：
            <textarea class="vt" v-model="errorContent">
            </textarea>
          </p>
          <div class="auto tc">
            <button class="blue-button xl-btn-css" @click="onErrorSubmit">确认</button>
            <button class="blue-button xl-btn-css" @click="errShow=false">取消</button>
          </div>
        </div>
      </div>
    </vodal>
    <vodal :show="clockShow" animation="zoom" :width="420" :height="480" @hide="clockShow=false">
      <form @submit.prevent="onClockSubmit">
        <div class="vodal-main clock">
          <h4>设置提醒闹钟</h4>
          <ul>
            <li>
              <h5>闹钟时间：</h5>
              <div class="box">
                <calendar value="" format="yyyy-MM-dd" width="95px" placeholder="年-月-日" ref="time"></calendar>
                <select v-model="hour" class="time vt">
                  <option value="">--</option>
                  <option v-for="n in 24">{{n | numFilter}}</option>
                </select>时：
                <select v-model="minute" class="time vt">
                  <option value="">--</option>
                  <option v-for="n in 60">{{n | numFilter}}</option>
                </select>分
              </div>
            </li>
            <li>
              <h5>提醒内容：</h5>
              <div class="box">
                <p> <span>提醒事件：</span>
                  <select v-model="content">
                    <option value="">提醒事件</option>
                    <option :value="item.content" v-for="item in eventList">{{item.content}}</option>
                  </select>
                </p>
                <p><span>备注：</span>
                  <textarea class="vt" v-model="clockRemark"></textarea>
                </p>
              </div>
            </li>
            <li>
              <h5>多方提醒：</h5>
              <div class="box">
                <div class="dib">
                  <input type="checkbox" id="10" :value="user" v-model="userInfo">
                  <label for="10" class="vt">自己</label>
                </div>
                <div class="dib" v-for="(item,i) in memberList">
                  <input type="checkbox" :id="i" :value="i" v-model="indexList">
                  <label :for="i">{{item.memberName}}</label>
                </div>
              </div>
            </li>
          </ul>
          <div class="auto tc">
            <button type="submit" class="blue-button xl-btn-css">确认</button>
            <button type="button" class="blue-button xl-btn-css" @click="clockShow=false">取消</button>
          </div>
        </div>
      </form>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import CompanyNameContainer from '../components/CompanyNameContainer'
import EventItem from '../components/EventItem'
import calendar from '../components/Calendar'
export default {
  components: {
    CompanyNameContainer,
    EventItem,
    calendar
  },
  data() {
    return {
      id: '',
      stepNum: 3,
      stepData: [{
        name: '查看资质审查报告'
      }, {
        name: '查看审查合同'
      }, {
        name: '监控师绘制流程图'
      }, {
        name: '监控员交易监控'
      }],
      companyNames: [],
      events: [],
      remark: '',
      megShow: false,
      errShow: false,
      clockShow: false,
      msgContent: '',
      content: '',
      hour: '',
      minute: '',
      state: 0,
      businessList: [],
      checkedNames: [],
      errorContent: '',
      eventList: [],
      memberList: [],
      relationIds: '',
      indexList: [],
      clockRemark: '',
      userInfo: []
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this.getData()
  },
  methods: {
    getData() {
      this.$http.post('/transactionMonitorSer/sys/read/detail', {
        id: this.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.state = data.data.data.status
          this.remark = data.data.data.remark
          this.eventList = data.data.data.eventList
          this.eventList.forEach(item => {
            let event = {}
            event.content = item.content
            event.side = item.memberOrder
            event.state = item.status
            event.files = item.fileList || []
            event.index = item.order
            event.id = item.id
            this.events.push(event)
          })
          data.data.data.memberList.forEach(member => {
            this.companyNames.push({
              name: member.memberName,
              id: member.id
            })
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onMsg() {
      this.$http.post('/transactionMonitorSer/center/prUploadReport', {
        id: this.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.megShow = true
          this.businessList = data.data.rows
          console.log(this.businessList)
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onMsgSubmit() {
      if (!this.msgContent) {
        this.$toasted.show('消息内容不能为空')
        return
      }
      if (this.checkedNames.length === 0) {
        this.$toasted.show('请选择发送方')
        return
      }
      this.$http.post('/message/send/trade/background', {
        orderId: this.id,
        msgContent: this.msgContent,
        reciveArr: this.checkedNames
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('发送成功')
          this.megShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onErrorSubmit() {
      if (!this.errorContent) {
        this.$toasted.show('内容不能为空')
        return
      }
      this.$http.post('/tradeError/send/trade/error', {
        orderid: this.id,
        recivedType: 2,
        errorContent: this.errorContent
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('发送成功')
          this.errShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    clockButton() {
      this.$http.post('/transactionMonitorSer/center/prUploadReport', {
       id: this.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.memberList = data.data.rows
          this.clockShow = true
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onClockSubmit() {
      if (!this.$refs.time.inputValue) {
        this.$toasted.show('请选择年月日')
        return
      }
      if (!this.hour) {
        this.$toasted.show('请选择时')
        return
      }
      if (!this.minute) {
        this.$toasted.show('请选择分')
        return
      }
      if (!this.content) {
        this.$toasted.show('请选择提醒事件')
        return
      }
      if (!this.clockRemark) {
        this.$toasted.show('请填写备注')
        return
      }
      if (this.userInfo.length) {
        this.relationIds = this.userInfo[0].split(',')[0] + ','
        this.relationNames = '交易监控员' + this.userInfo[0].split(',')[1] + ','
      } else {
        this.relationNames = ''
      }
      this.indexList.forEach(i => {
        this.relationIds += this.memberList[i].memberId + ','
        this.relationNames += this.memberList[i].memberName + ','
      })
      if (this.relationIds.length === 0) {
        this.$toasted.show('请选择提醒方')
        return
      }
      this.$http.get('/sysClock/clock', {
        params: {
          time: this.$refs.time.inputValue + ' ' + this.hour + ':' + this.minute + ':00',
          relationId: this.$route.query.id,
          content: this.content,
          relationIds: this.relationIds.substring(0, this.relationIds.lastIndexOf(',')),
          relationNames: this.relationNames.substring(0, this.relationNames.lastIndexOf(',')),
          remark: this.clockRemark
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('提交成功')
          this.clockShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    }
  },
  computed: {
    user() {
      return this.$store.state.userInfo.id + ',' + this.$store.state.userInfo.account
    }
  },
  filters: {
    numFilter(v) {
      if (v > 1 && v < 11) {
        return 0 + (v - 1).toString()
      } else {
        return v - 1
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.content {
  padding-bottom: 30px;
  margin-top: 20px;
}

.content h3 {
  line-height: 40px;
  border-bottom: 1px solid #ddd;
}

.line {
  position: absolute;
  width: 2px;
  top: 0;
  left: 65px;
  margin-top: 10px;
  background-color: #cfcfcf;
}

.line.center {
  left: 50%;
}

.line .arrow {
  position: absolute;
  bottom: -10px;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid #cfcfcf;
}

.content p {
  margin-top: 50px;
}

.content h4 {
  padding-left: 30px;
  font-size: 14px;
  line-height: 30px;
  border-bottom: 1px solid #ddd;
}

.note-box {
  padding: 10px;
  text-indent: 20px;
  line-height: 30px;
}

.title-btn {
  right: 10px;
  top: 6px;
}

.title-btn button {
  margin-left: 10px;
}

.message .fix {
  height: 89px;
}

.message .con p {
  margin-bottom: 12px;
}

textarea {
  width: 300px;
  height: 120px;
  padding: 10px 8px;
}

.message .con ul {
  width: 300px;
  margin-left: 5px;
}

.message .con ul li {
  display: inline-block;
  padding-top: 0;
  margin-right: 15px;
  margin-bottom: 10px;
}

.vodal-main .con button {
  margin: 15px 10px 0 10px;
}

.clock h5 {
  padding-left: 30px;
  line-height: 35px;
  font-weight: bolder;
  margin-top: 10px;
}

.clock li .box {
  padding: 0px 45px;
}

.clock li .box p {
  margin-bottom: 15px;
}

.clock li .box select {
  border: 1px solid #ddd;
  height: 35px;
  width: 150px;
  color: #2f2f2f;
}

.clock li .box span {
  display: inline-block;
  width: 70px;
  text-align: right;
}

.clock li .box .time {
  width: 40px;
  height: 40px;
}

.clock li .box textarea {
  width: 250px;
  height: 80px;
}

.clock li .box .dib {
  margin-right: 15px;
  margin-bottom: 8px;
}

.clock button {
  margin: 20px 10px 0 10px;
}

.progress-box {
  overflow-y: auto;
  overflow-x: auto;
}

</style>
